home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1998 July / EnigmA AMIGA RUN 29 (1998)(G.R. Edizioni)(IT)[!][issue 1998-07 & 08].iso / earkit / news / thor / rexx / bbsread / bouncemsg.br < prev    next >
Text File  |  1998-05-24  |  4KB  |  182 lines

  1. /*
  2. ** $VER: BounceMsg.br 1.0 (13.5.97)
  3. ** by Eirik Nicolai Synnes
  4. **
  5. */
  6.  
  7. options results
  8. options failat 31
  9.  
  10. parse arg arguments
  11.  
  12. template = 'SYSTEM/A,CONFERENCE/A,MSGNO/A/N,USERLIST/A,BCC/S'
  13.  
  14.  
  15. /*
  16. ** INITIALIZATION
  17. */
  18.  
  19. EVE_ENTERMSG      =  0        /* Enter message */
  20. EVE_REPLYMSG      =  1        /* Reply message */
  21. EVE_FORWARDMSG    =  9        /* Forward message (only TCP/SOUP) */
  22.  
  23. MDB_URGENT        = 11        /* Message is urgent.    */
  24. MDB_RETURNRECEIPT = 26
  25. MDB_ENCODE8BIT    = 27
  26.  
  27.  
  28. /*
  29. ** Check if BBSREAD's ARexx port is open, open it if it's not
  30. */
  31.  
  32. if ~(show('P', 'BBSREAD')) then do
  33.     address(command)
  34.     'Run >NIL: `GetEnv THOR/THORPath`bin/LoadBBSRead'
  35.     if exists('SYS:RexxC/WaitForPort') then 'SYS:RexxC/WaitForPort BBSREAD'
  36.     else 'WaitForPort BBSREAD'
  37.     if (rc = 5) then do; say 'Could not open BBSREAD''s ARexx port.'; exit(30); end
  38.     if (rc ~= 0) then do; say 'Could not find SYS:Rexxc/WaitForPort.'; exit(30); end
  39.     end
  40.  
  41.  
  42. /*
  43. ** Parse command line
  44. */
  45.  
  46. if (arguments = '') | (arguments = '?') then do
  47.     say 'Template: 'template
  48.     say 'BounceMsg.br is an external script for SortMail.'
  49.     exit(20)
  50.     end
  51.  
  52. address(bbsread)
  53. 'READARGS 'template args' CMDLINE 'arguments
  54. if (rc ~= 0) then do
  55.     say 'Template: 'template
  56.     say 'READARGS failed: 'BBSREAD.LASTERROR
  57.     exit(rc)
  58.     end
  59.  
  60.  
  61. /*
  62. ** Get system and message data
  63. */
  64.  
  65. 'GETBBSDATA "'args.system'" 'bbsdata
  66. if (rc ~= 0) then do
  67.     say 'GETBBSDATA: 'BBSREAD.LASTERROR
  68.     exit(rc)
  69.     end
  70.  
  71. if (symbol('bbsdata.EMAILADDR') ~= 'VAR') then do
  72.     say 'No email address configured for system "' || bbsdata.NAME || '".'
  73.     exit(20)
  74.     end
  75.  
  76. 'READBRMESSAGE "'args.system'" "'args.conference'" 'args.MSGNO' DATASTEM 'msgdata' HEADSTEM 'msghead
  77. if (rc ~= 0) then do
  78.     say 'READBRMESSAGE, data & head stem: 'BBSREAD.LASTERROR
  79.     exit(rc)
  80.     end
  81.  
  82. /*
  83. ** See if the message is from the local user, exit if so
  84. */
  85.  
  86. if (msghead.FROMADDR = bbsdata.EMAILADDR) then exit(0)
  87.  
  88.  
  89. /*
  90. ** Get addresses to mail message to
  91. */
  92.  
  93. 'SEARCHBRUSER "'args.system'" STEM 'user' SEARCH "'args.USERLIST'" NAME'
  94. if (rc ~= 0) then do
  95.     say 'SEARCHBRUSER: 'BBSREAD.LASTERROR
  96.     exit(rc)
  97.     end
  98.  
  99. if (result = 0) then do
  100.     say 'No user with the name "'args.USERLIST'".'
  101.     exit(20)
  102.     end
  103.  
  104. 'READBRUSER BBSNAME "'args.system'" USERNR 'user.1.USERNR' TAGSSTEM 'usertags' DATASTEM 'userdata
  105. if (rc ~= 0) then do
  106.     say 'READBRUSER: 'BBSREAD.LASTERROR
  107.     exit(rc)
  108.     end
  109.  
  110. if (symbol('usertags.ADDRESS') ~= 'VAR') | (strip(usertags.ADDRESS, 'B') = '') then do
  111.     say 'User "'args.USERLIST'" does not have any addresses defined.'
  112.     exit(20)
  113.     end
  114.  
  115.  
  116. /*
  117. ** Get global configuration
  118. */
  119.  
  120. 'GETGLOBALDATA 'globdata
  121. if (rc ~= 0) then do
  122.     say 'GETGLOBALDATA: 'BBSREAD.LASTERROR
  123.     exit(rc)
  124.     end
  125.  
  126. if (right(globdata.TMPDIR, 1) ~= '/') & (right(globdata.TMPDIR, 1) ~= ':') then globdata.TMPDIR = globdata.TMPDIR || '/'
  127.  
  128.  
  129. /*
  130. ** Create event data
  131. */
  132.  
  133. eventdata.TOADDR        = bbsdata.EMAILADDR
  134. eventdata.TONAME        = usertags.NAME
  135. eventdata.SUBJECT       = msghead.SUBJECT
  136. eventdata.CONFERENCE    = 'EMail'
  137. eventdata.REFCONFERENCE = args.CONFERENCE
  138. eventdata.REFNR         = args.MSGNO
  139.  
  140. if (symbol('msghead.MSGID') = 'VAR')          then eventdata.REFID         = msghead.MSGID
  141. if (bittst(msgdata.flags, MDB_URGENT))        then eventdata.URGENT        = 1; else eventdata.URGENT        = 0
  142. if (bittst(msgdata.flags, MDB_RETURNRECEIPT)) then eventdata.RETURNRECEIPT = 1; else eventdata.RETURNRECEIPT = 0
  143. if (bittst(msgdata.flags, MDB_ENCODE8BIT))    then eventdata.ENCODE8BIT    = 1; else eventdata.ENCODE8BIT    = 0
  144.  
  145.  
  146. /*
  147. ** Create message file with headers
  148. */
  149.  
  150. 'UNIQUEMSGFILE BBSNAME "'args.system'" STEM 'msgfile
  151. if (rc ~= 0) then do
  152.     say 'UNIQUEMSGFILE: 'BBSREAD.LASTERROR
  153.     exit(rc)
  154.     end
  155.  
  156. eventdata.MSGFILE = msgfile.FILEPART
  157.  
  158. if open(msgf, msgfile.NAME, 'A') then do
  159.     call writeln(msgf, 'From: ' || msghead.FROMNAME || ' <' || msghead.FROMADDR || '>')
  160.     call writeln(msgf, 'Reply-To: ' || bbsdata.EMAILADDR)
  161.     if (args.BCC) then call writeln(msgf, 'Bcc: ' || usertags.ADDRESS)
  162.     else call writeln(msgf, 'Cc: ' || usertags.ADDRESS)
  163.     call close(msgf)
  164.     end
  165. else do
  166.     say 'Could not open message file.'
  167.     exit(20)
  168.     end
  169.  
  170.  
  171. /*
  172. ** Write the new event
  173. */
  174.  
  175. 'WRITEBREVENT BBSNAME "'args.system'" EVENT 'EVE_FORWARDMSG' STEM 'eventdata
  176. if (rc ~= 0) then do
  177.     say 'WRITEBREVENT: 'BBSREAD.LASTERROR
  178.     exit(rc)
  179.     end
  180.  
  181. exit(0)
  182.